package com.study.web.service.syspermission.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.study.common.base.dao.BaseDao;
import com.study.common.base.service.BaseServiceImpl;
import com.study.common.exception.BizException;
import com.study.web.dao.syspermission.SysPermissionDao;
import com.study.web.dto.PermissionDto;
import com.study.web.entity.SysPermission;
import com.study.web.entity.SysRolePermission;
import com.study.web.service.syspermission.SysPermissionService;

/**
 * SysPermissionServiceImpl.java
 * @author yaojinshan
 * @since 2018年6月11日下午5:00:21
 */
@Service("sysPermissionService")
public class SysPermissionServiceImpl extends BaseServiceImpl<SysPermission>implements SysPermissionService {
	@Resource
	private SysPermissionDao sysPermissionDao;
	@Override
	protected BaseDao<SysPermission> getDao() {
		return sysPermissionDao;
	}

	public List<Map<String,Object>> queryMenuDtoListByParentIdAndRoleId(Map<String,Object> paramsMap) throws BizException {
		return sysPermissionDao.queryMenuDtoListByParentIdAndRoleId(paramsMap);
	}

	public List<SysPermission> queryFirstLevelMenuByRoleId(Map<String, Object> paramsMap) {
		return sysPermissionDao.queryFirstLevelMenuByRoleId(paramsMap);
	}

	public List<PermissionDto> queryPermisssonOfRole(Map<String, Object> allUseableRolePermisssonParamMap) {
		return sysPermissionDao.queryPermisssonOfRole(allUseableRolePermisssonParamMap);
	}
	
	@Transactional
	public void deleteOldRolePermissionAndBatchInsert(List<Long> ids, Long roleId) {
		sysPermissionDao.deleteOldRolePermission(roleId);
		if(null != ids && ids.size() > 0){
			List<SysRolePermission> list = new ArrayList<SysRolePermission>();
			for (Long id : ids) {
				SysRolePermission srp = new SysRolePermission(roleId,id);
				list.add(srp);
			}
			sysPermissionDao.batchInsertRolePermission(list);
		}
	}

}
